<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>北京联合大学</title>
</head>
<!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="https://at.alicdn.com/t/font_835526_cs2s2fdumkp.css">
<link rel="stylesheet" href="../../css/Initialization.css">
<link rel="stylesheet" href="../../css/commen.css">
<link rel="stylesheet" href="../../css/personinfo.css">
<link rel="stylesheet" href="../../css/UploadResults.css">
<link rel="stylesheet" href="../../css/unit.css">
<body>
<div id="content">
    <div class="initer">
            <!-- 具体内容 -->
            <!-- 单元知识点 具体内容 -->
            <div class="bread">
                <div class="plain">
                    我的信息
                </div>
                <div class="plain">
                    <i class="iconfont icon-right"></i>
                </div>
                <div class="plain current">
                    个人信息
                </div>
                <div class="center-button" id="savemessage">保存信息</div>
            </div>
            <!-- 个人信息 -->
        <div>
            <div class="personinfo">
                <div class="tableinfo">
                    <div class="table">
                        <table>
                            <tr>
                                <td>
                                    <!-- <i class="iconfont icon-wo"></i> -->
                                    <img src="../../imgs/user.png" alt="">
                                    <span>姓名</span>
                                </td>
                                <td th:text="${person.realname}">李国庆</td>
                            </tr>
                            <tr>
                                <td>
                                    <!-- <i class="iconfont icon-xingbie"></i> -->
                                    <img src="../../imgs/sex.png" alt="">
                                    <span>性别</span>
                                </td>
                                <td th:if="${person.sex == 0}">男</td>
                                <td th:if="${person.sex == 1}">女</td>
                            </tr>
                            <tr>
                                <td>
                                    <!-- <i class="iconfont icon-gongandunpai"></i> -->
                                    <img src="../../imgs/class.png" alt="" class="nianji">
                                    <span>班级</span>
                                </td>
                                <td th:text="${person.departname}">班级</td>
                            </tr>
                            <tr>
                                <td>
                                    <!-- <i class="iconfont icon-renshu"></i> -->
                                    <img src="../../imgs/name.png" alt="" >
                                    <span>年级</span>
                                </td>
                                <td th:text="${person.gradename}">年级</td>
                            </tr>
                            <tr>
                                <td>
                                    <!-- <i class="iconfont icon-mingpian2"></i> -->
                                    <img src="../../imgs/xuehao.png" alt="">
                                    <span>学号</span>
                                </td>
                                <td th:text="${person.userno}">学号</td>
                            </tr>
                        </table>
                    </div>
                    <div class="jianjie">
                        <div class="header">
                            <!-- <i class="iconfont icon-jianjie"></i> -->
                            <img src="../../imgs/jianjie.png" alt="">
                            <span>简介</span>
                        </div>
                        <textarea class="desc" th:text="${person.profile}" id="profile" name="profile"></textarea>
                    </div>
                    <div class="photo">
                        <img th:src="${person.imgface}" alt="">
                        <div class="center-button">更改照片 <input type="file" class="file" name='file' id='file'>  </div>
                    </div>
                </div>

                <!-- 确认退出小组 -->
                <div class="mask none">
                    <div class="sureteam">
                        <div class="title">
                            确认退出小组
                        </div>
                        <div class="teamcenter">
                            <div class="teamdesc_tip" id="resultmessage">
                                你是否确定退出“<span id="groupname"></span>”小组？
                            </div>
                            <div class="surebtns">
                                <div class="center-button" id="yesexit">确认退出</div>
                                <div class="center-button" id="noexit">暂不退出</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="teaminfo" th:if="${person.isjoin != 0}">
                <div class="topheader">
                    <span>我的小组信息</span>
                    <span class="center-button" style="position:relative;" th:if="${person.isjoin == 2 && group.state == 0}">退出小组<a href="javascript:void(0)" id="exitGroup" th:onclick="'javascript:exitGroup()'" style="position: absolute;left: 0;right: 0;top: 0;bottom: 0;"></a></span>
                </div>
                <div class="teamdesc">
                    <div class="teamtitle green" th:text="${group.groupname}" id="groupnameText">打造一个世界500强</div>
                    <div class="desc" th:text="${group.groupintro}">小组说明小组说明小组说明小组说明小组说明小组说明小组说明</div>
                </div>
            </div>

            <div class="teaminfo" th:if="${person.isjoin == 0}">
                <div class="topheader">
                    <span>我的小组信息</span>
                </div>
                <div class="teamdesc">
                    <div class="opctionsbuttons">
                        <span class="center-button" style="margin-right: 20px;" onclick="location.href='../StudentGroup/addGroup'">创建小组</span>
                        <span class="center-button" onclick="location.href='../StudentGroup/grouplist'">加入小组</span>
                    </div>
                </div>
            </div>
        </div>



        </div>
</div>

<script src="../../js/jquery-3.4.1.min.js"></script>
<script src="../../js/commen.js"></script>
<script>

    function exitGroup() {
        var groupname = $("#groupnameText").html();
        $("#groupname").html(groupname);
        $('.mask').removeClass('none');
    }

    function change(json){
        $("#resultmessage").html(json.result);
        $("#yesexit").hide();
        $("#noexit").html("确定");
        if(json.state == success){
            $("#noexit").click(function () {
                location.reload();
            });
        }else{
            $("#noexit").click(function () {
                $('.mask').addClass('none');
            });
        }
    }

    $(function () {
        $("#savemessage").click(function () {
            var profile = $("#profile").val();
            $.ajax({
                type : "POST",
                url : "updateProfile",
                data : {profile: profile},
                dataType : "json",
                success : function(json) {
                    alert(json.result);
                    if(json.state == success){
                        location.reload();
                    }
                },
                error:function(msg){
                    alert("程序出错，请联系管理员");
                }
            });
        });

        $("#noexit").click(function () {
            $('.mask').addClass('none');
        });

        $("#yesexit").click(function () {
            $.ajax({
                type : "POST",
                url : "../StudentGroup/exitGroup",
                data : {userid: 0},
                dataType : "json",
                success : function(json) {
                    console.log(json)
                    alert(json.result);
                    if(json.state == success){
                        location.reload();
                    }
                },
                error:function(msg){
                    alert("程序出错，请联系管理员");
                }
            });
        });

        $("#file").change(function () {
            if($(this).val() != ""){
                var formData = new FormData();
                formData.append("file", document.getElementById("file").files[0]);
                $.ajax({
                    url: "/file/upload",
                    type: "POST",
                    data: formData,
                    contentType: false,
                    processData: false,
                    dataType:"json",
                    success: function (data) {
                        if(data.state == success){
                            $.ajax({
                                type : "POST",
                                url : "updateHeadimg",
                                data : {imgface: data.data},
                                dataType : "json",
                                success : function(json) {
                                    alert(json.result);
                                    if(json.state == success){
                                        location.reload();
                                    }
                                },
                                error:function(msg){
                                    alert("程序出错，请联系管理员");
                                }
                            });
                        }else if(data.state == error){
                            alert(data.result);
                        }
                    },
                    error: function () {
                        alert("上传失败！");
                    }
                });
            }
        })
    })
</script>
</body>
</html>
